﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ufolder
{
    public partial class TagsPalette : Form
    {
        private Label[] tags;

        public TagsPalette()
        {
            InitializeComponent();
        }

        public void Display(Label[] tags)
        {
            this.tags = tags;            
            this.Invalidate();


        }

        private void pictureBox_Paint(object sender, PaintEventArgs e)
        {
            Font bigFont = new Font(this.Font.FontFamily, 30);
            Font smallFont = new Font(this.Font.FontFamily, 15);
            string l = null;
            int vBigSpace = 5;
            int htBigSpace = 5;
            int vSmallSpace = 3;
            int hSmallSpace = 3;
            int col = 0;
            int row = 0;
            int maxPCol = 0;
            int maxPSubCol = 3;
            int curVDraw = 0;
            int curHDraw = 0;

            e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

            int VCumul = 0;
            int i = 0;

            int nbrTag = tags.Length;
            for(i = 0; i < nbrTag; i++)
            {
                
                int hMaxLabel = 0;
                int vMaxLabel = 0;
                int VCumulSmall = 0;
                if (tags[i].LinkedTags != null)
                {
                    int nbrLinkedTag = tags[i].LinkedTags.Length;
                    for (int j = 0; j < nbrLinkedTag; j++)
                    {
                        VCumulSmall += (int)(vSmallSpace + smallFont.SizeInPoints);
                    }
                }

                VCumul += (int)(bigFont.SizeInPoints + vBigSpace) > VCumulSmall ? (int)(bigFont.SizeInPoints + vBigSpace) : VCumulSmall;

                if (VCumul > pictureBox.Height) 
                {
                    curHDraw += hMaxLabel + htBigSpace;
                    curVDraw = 0;
                }

                e.Graphics.DrawString(tags[i].Tag, bigFont, Brushes.Navy, curHDraw, curVDraw);
                curVDraw += (int)(bigFont.SizeInPoints + vBigSpace);

            }


        }
    }
}
